package Lesson19Notepad;

public class Page
{
	private String title;
	private String text = "";
	
	Page(String title)
	{
		if(title == null)
		{
			System.out.println(" Wrong title format!");
			this.title = "";
		}
		else
		{
		this.title = title;
		}
	}
	
	void addText (final String text)
	{
		if(this.text != null){
		this.text = this.text + "\n" + (text);
		}
		else
		{
			System.out.println("Wrong text input!");
		}
	}
	
	void delText()
	{
		this.text = "";
	}
	
	void readPage()
	{
		//System.out.println(this.title);
		System.out.println(text);
	}

	void searchWord (String word)
	{
		if(text.indexOf(word) != -1)
		{
			System.out.println("It's there any " + "\"" + word + "\"?" + " " + true);
		}
	}
	
	boolean containsDigits()
	{
		for (int i = 0; i < this.text.length(); i++) 
		{
			String str = "" + this.text.charAt(i);
			if (str.matches("[0-9]")) 
			{
				return true;
			}
		}
		return false;
	}
	
	
	@Override
	public boolean equals(Object obj)
	{
		if(obj instanceof Page)
		{
			return ((Page) obj).title.equals(this.title);
		}
		else
			return false;
	}
	
}
